import LDataCannon from "./datas/LDataCannon";
import UserInfo from "./UserInfo";
import Define from "./common/Define";
import Common from "./common/Common";
import LDataScene from "./datas/LDataScene";

// Learn TypeScript:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/typescript.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html

const {ccclass, property} = cc._decorator;

@ccclass
export default class SelectSceneItem extends cc.Component {

    @property(cc.Node)
    node_CannonRoot: cc.Node = null;

    @property(cc.Node)
    node_newTag: cc.Node = null;

    @property(cc.Node)
    node_useTag: cc.Node = null;

    @property(cc.Label)
    text_desc1: cc.Label = null;

    @property(cc.Label)
    text_desc2: cc.Label = null;

    
    @property(cc.Label)
    text_desc3: cc.Label = null;

    cannonData:LDataScene;

    start () {

    }

    refreshItemInfo(){
        this.text_desc1.string = ""
        this.text_desc2.string = ""
        this.text_desc3.string = ""

        this.node_newTag.active = false
        let isOwn:boolean = UserInfo.isOwnCannonById(this.cannonData.sceneId)
        if(isOwn){
            this.text_desc3.string = "已拥有"
            let state = UserInfo.getCannnonState(this.cannonData.sceneId)
            if(state == 1){ //说明是新获得的
                this.node_newTag.active = true
                this.node_newTag.stopAllActions();
                Common.actionLeftRightRotate(this.node_newTag,0.15,18,3)
            }
        }else{
            if(this.cannonData.getmode == Define.cannonVideo){
                this.text_desc1.string = "看视频免费\n获得"
            }else if(this.cannonData.getmode == Define.cannonTotalScore){
                this.text_desc1.string = "累积达到\n"+this.cannonData.scoreget + "分"
                let userTotalScore = UserInfo.totalScore;
                if(userTotalScore > this.cannonData.scoreget){
                    userTotalScore = this.cannonData.scoreget
                }   
                this.text_desc2.string = userTotalScore.toString() + "/" + this.cannonData.scoreget.toString()
            }else if(this.cannonData.getmode == Define.cannonDropGoldLevel){
                this.text_desc1.string = "将金币等级\n 升到"+((this.cannonData.goldlevel+10)*10).toString()+"%";
                this.text_desc2.string = ((UserInfo.goldDropLevel - 1)*10 + 100) +"%/"+((this.cannonData.goldlevel + 10)*10).toString()+"%";
            }else if(this.cannonData.getmode == Define.cannonShare){
                this.text_desc1.string = this.cannonData.cannontips
            }/*else if(this.cannonData.getmode == Define.cannonOffLine){
                this.text_desc1.string = "将离线等级\n 升到"+((this.cannonData.offline + 10)*10).toString()+"%";
                this.text_desc2.string = ((UserInfo.offLineLevel)*10 + 100) +"%/"+((this.cannonData.offline + 10)*10).toString()+"%";
            }*/
        }
        this.node_useTag.active = false
        if(this.cannonData.sceneId == UserInfo.curSceneId){
            this.node_useTag.active = true
        }
    }

    refreshItemInfoByData(data:LDataScene){
        this.cannonData = data;
        this.refreshItemInfo();
    }
}
